package com.bocloud.cmp.driver.providers.impl;

import org.springframework.stereotype.Service;

import com.bocloud.cmp.driver.config.Configuration;
import com.bocloud.cmp.driver.providers.VdcDriver;
import com.bocloud.cmp.driver.providers.intf.VdcProvider;
import com.bocloud.cmp.driver.providers.vmware.VmwareVdcDriver;
import com.bocloud.cmp.driver.utils.VendorConverter;
import com.bocloud.cmp.enums.VendorType;
import com.bocloud.cmp.model.Butler;
import com.bocloud.common.model.BsmResult;

/**
 * 数据中心操作服务接口实现类
 * 
 * @author weiwei
 *
 */
@Service("vdcProvider")
public class VdcProviderImpl implements VdcProvider {

	@Override
	public BsmResult list(String vendor) {
		VdcDriver driver = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case VMWARE:
			driver = new VmwareVdcDriver(butler.getUrl(), butler.getUsername(), butler.getPassword());
			break;
		default:
			break;
		}
		if (null == driver) {
			return new BsmResult(false, "暂不支持！");
		} else if (!driver.accessable()) {
			return new BsmResult(false, "用户鉴权失败！");
		} else {
			return driver.list();
		}
	}
}
